<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>更换壁纸</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }
        ul {
            list-style: none;
            overflow: hidden;
            width: 1200px;
            margin: 0 auto;
            background:rgba(255, 255, 255, 0.4) 
        }
        #skin {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-position: center 0;
            background-repeat: no-repeat;
        }
        #skin-photo {
            width: 100%;
            height: 100px;
            position: relative;
            z-index: 10
        }
        ul li {
            float:left;
            margin: 10px 0 10px 96px;
            cursor: pointer;
            height: 120px;
        }
        li img {
            width: 180px;
            height: 120px;
        }
    </style>
</head>
<body>
    <div id="skin"><img src="images/haizei1.jpg" id="cao"></div>
    <div id="skin-photo">
        <ul>
            <li><img src="images/haizei1.jpg"></li>
            <li><img src="images/haizei2.jpg"></li>
            <li><img src="images/haizei3.jpg"></li>
            <li><img src="images/haizei4.jpg"></li>
        </ul>
    </div>
    <script>
        var skin=document.getElementById('skin');
        var cao=document.getElementById('cao');
        var allItems=document.getElementsByTagName('li');
        for(var i=0;i<allItems.length;i++){
            allItems[i].index=i+1;
            allItems[i].onclick=function(){
                cao.setAttribute('src',`images/haizei${this.index}.jpg`);
                // skin.style.backgroundImage='url(`images/haizei${this.index}.jpg`)';
            }
        }
        
    </script>
</body>
</html>